package cn.wolfcode.config;

import cn.wolfcode.web.interceptor.LoginInterceptor;
import cn.wolfcode.web.interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  配置类
 *  配置拦截器，可配置多个
 *
 */
@Configuration
public class MvcJavaConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor; // 登录拦截器
    @Autowired
    private PermissionInterceptor permissionInterceptor; //访问权限

    public void addInterceptors(InterceptorRegistry registry) {

        // 登录拦截器
        registry.addInterceptor(loginInterceptor)
                // 拦截路径,可配置多个  .addPathPatterns("/**", "/employee/list")
                .addPathPatterns("/**")
                // 排除路径,可配置多个(访问排除的路径，就不会进入到拦截器里面)
                .excludePathPatterns("/login", "/static/**")
                //.excludePathPatterns("/user/**")
                ;
        // 访问权限拦截
        registry.addInterceptor(permissionInterceptor)
                // 拦截路径,可配置多个
                .addPathPatterns("/**")
                // 排除路径,可配置多个(访问排除的路径，就不会进入到拦截器里面)
                .excludePathPatterns("/login", "/static/**");
    }
}
